package service

import (
	"bytes"
	"gin-vue-admin/global"
	"gin-vue-admin/utils"
	"io"
	"net/http"
	"time"
)



// 发送GET请求
// url：         请求地址
// response：    请求返回的内容
func Get(url string) string {

	// 超时时间：5秒
	client := &http.Client{Timeout: 5 * time.Second}
	resp, err := client.Get(url)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	var buffer [512]byte
	result := bytes.NewBuffer(nil)
	for {
		n, err := resp.Body.Read(buffer[0:])
		result.Write(buffer[0:n])
		if err != nil && err == io.EOF {
			break
		} else if err != nil {
			panic(err)
		}
	}

	return result.String()
}


//@author: [maplepie](https://github.com/maplepie)
//@function: EmailTest
//@description: 发送邮件测试
//@return: err error

func EmailTest() (err error) {
    var TextStr string =Get("https://api.vvhan.com/api/love");
	subject := "爱你的奇"
	body := TextStr
	global.GVA_LOG.Info(body)
	err = utils.EmailTest(subject, body)
	return err
}
